package com.cosmoplat.xikai.business.job;


import com.cosmoplat.xikai.business.service.DeviceCallService;
import com.cosmoplat.xikai.business.service.JobService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 设备定时任务
 */
@Component("deviceTask")
@Slf4j
public class DeviceTask {
    @Autowired
    private DeviceCallService deviceCallService;

    @Autowired
    private JobService jobService;

    /**
     * 设备实时数据保存
     * @param deviceCodes
     */
    public void deviceCall(String deviceCodes) {
        log.debug("设备实时数据保存-开始");
        try {
            deviceCallService.saveData(deviceCodes);
        } catch (Exception e) {
            log.error("设备实时数据保存执行异常:{}", e);
        }
        log.debug("设备实时数据保存--完成");
    }
    /**
     * 设备能耗
     * @param deviceCodes
     */
    public void  energyConsumptionRate(String deviceCodes) {
        log.debug("设备能耗-开始");
        try {
            deviceCallService.getEnergyConsumptionRate(deviceCodes);
        } catch (Exception e) {
            log.error("设备能耗保存执行异常:{}", e);
        }
        log.debug("设备能耗--完成");
    }

    /**
     * 设备状态统计
     * @param deviceCode
     */
    public void deviceStatusStatistics(String deviceCode) {
        log.debug("设备状态统计-开始");
        try {
            jobService.deviceStatusStatistics(deviceCode);
        } catch (Exception e) {
            log.error("设备状态统计执行异常:{}", e);
        }
        log.debug("设备状态统计-完成");
    }


}
